<template>
  <div id="collect">
    <div class="nav">
      <van-nav-bar title="我的收藏" left-text="返回" left-arrow @click-left="onClickLeft" />
    </div>

    <div class="list-show">
      <ul class="list-cont">
        <li
          class="list-item"
          v-for="item in list.collectGoodsList"
          :key="item.id"
          @click="toGoodDetail(item.id)"
        >
          <img :src="item.list_pic_url" />
          <p class="item-name">{{item.name}}</p>
          <p class="item-price">￥ {{item.retail_price}}</p>
        </li>
        <li class="last"></li>
      </ul>
    </div>
  </div>
</template>

<script>
import { collectListAction } from "@/api/mine/collect";
export default {
  data() {
    return {
      list: [],
    };
  },
  created() {
    collectListAction({
      openId: localStorage.getItem("openId"),
    }).then((res) => {
      this.list = res;
    });
  },
  methods: {
    toGoodDetail(val) {
      this.$router.push({ path: "/goods", query: { id: val } });
    },
    onClickLeft() {
      this.$router.go(-1);
    },
  },
};
</script>

<style lang="scss" scoped>
#goods {
  background-color: rgb(244, 244, 244);
  height: 100%;
  overflow: auto;
}
.nav {
  position: fixed;
  width: 375px;
  top: 0;
  left: 0;
  z-index: 99;
}

.list-show {
  width: 375px;
  margin-top: 50px;
  .list-cont {
    width: 375px;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-evenly;
    .list-item {
      width: 180px;
      height: 220px;
      padding: 0 15px;
      margin-bottom: 5px;
      background-color: #fff;
      box-sizing: border-box;
      img {
        width: 150px;
        height: 150px;
      }
      .item-name {
        width: 150px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        margin-bottom: 10px;
        font-size: 12px;
      }
      .item-price {
        width: 150px;
        color: rgb(165, 50, 50);
        font-size: 12px;
      }
    }
    .last {
      width: 180px;
      height: 0;
      padding: 0;
      margin: 0;
    }
  }
}
</style>